package com.spukmk3me.util;

public abstract class ReferenceCounted
{
    public final void inc()
    {
        ++m_counter;
    }

    public final void dec()
    {
        //System.out.println( this + " dec. " + m_counter + " remain." );
        
        if ( m_counter != 0 )
        {
            if ( --m_counter == 0 )
                onZeroCounter();
        }
    }
    
    public final int getCounter()
    {
        return m_counter;
    }
    
    protected abstract void onZeroCounter();
    
    private int m_counter;
}
